# NOTE: some drag & drop stuff is in Mouse.boo as well!
namespace Vanilla.UI

import System

partial class Gadget:
	// DRAG + DROP
	public static GadgetBeingDragged as Gadget = null
	public static ParentOfGadgetBeingDragged as Box = null
	
	public CanDrag = false
	public CloneOnDrag = false
	public AcceptsDrops = false
	
	public BeingDragged as bool:
		get:
			return GadgetBeingDragged == self
	
	virtual def UndoDragFrom (p as Box):
		p.Drop(self, Position.X, Position.Y)
	
	static def CleanUpAndEndDrag ():
		backend_CleanUpAndEndDrag()
		GadgetBeingDragged = null
		ParentOfGadgetBeingDragged = null
	
	static def CancelDrag ():
		return if GadgetBeingDragged == null
		
		GadgetBeingDragged.UndoDragFrom(ParentOfGadgetBeingDragged)
	
	virtual def AcceptsDrop (g as Gadget, x as double, y as double):
		return self isa Box and AcceptsDrops and Size.Contains(x,y)
	
	virtual def Drop (g as Gadget, x as double, y as double):
		//print "${GetType()} droptatoes"
		//CleanUpAndEndDrag()
		CancelDrag()
	
	virtual def Drag ():
		//if CloneOnDrag:
		//	GadgetBeingDragged = Clone()
		//	backend_Drag(self)
		//else:
			ParentOfGadgetBeingDragged = Parent
			Parent.Remove(self)
			GadgetBeingDragged = self
			backend_Drag(self)
		
